#pragma once

#include<vector>
#include<iostream>
template<size_t N>
class bitset
{
public:
	bitset()
	{
		_bits.resize(N / 8 + 1, 0);
	}

	void set(size_t x)
	{
		size_t i = x / 8;
		size_t j = x % 8;
		_bits[i] |= (1 << j);
	}

	void reset(size_t x)
	{
		size_t i = x / 8;
		size_t j = x % 8;

		_bits[i] &= ~(1 << j);
	}

	bool test(size_t x)
	{
		size_t i = x / 8;
		size_t j = x % 8;

		return _bits[i] & (1<<j);
	}
private:
	vector<char> _bits;
};


void test_bitset1()
{
	bitset<100> bs;
	bs.set(10);
	bs.set(11);
	bs.set(15);
	cout << bs.test(10) << endl;
	cout << bs.test(15) << endl;

	bs.reset(10);

	cout << bs.test(10) << endl;
	cout << bs.test(15) << endl;

	bs.reset(10);
	bs.reset(15);

	cout << bs.test(10) << endl;
	cout << bs.test(15) << endl;
}

void test_bitset2()
{
	//bitset<-1> bs1;
	bitset<0xFFFFFFFF> bs1;
}


template<size_t N>
class twobitset
{
public:
	void set(size_t x)
	{
		if (_bst1.test(x) == false && _bst2.test(x) == false)
		{
			_bst2.set(x);
		}
		else if (_bst1.test(x) == false && _bst2.test(x) == true)
		{
			_bst1.set(x);
			_bst2.reset(x);
		}
	}

	void print()
	{
		for (size_t i = 0; i < N; ++i)
		{
			if (_bst2.test(i))
				cout << i << " ";
		}
	}

private:
	bitset<N> _bst1;
	bitset<N> _bst2;
};

void test_twobitset()
{
	int a[] = { 3, 45, 53, 32, 32, 43, 3, 2, 5, 2, 32, 55, 5, 53,43,9,8,7,8 };
	twobitset<100> bs;
	for (auto e : a)
	{
		bs.set(e);
	}

	bs.print();
}